<template>
	<view>
		<view class="detail-box">
			<view class="cu-form-group">
				<view class="title">商品名称：</view>
				<input class="inpt" name="input" :value="NowSelectGoods.GoodsName"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">编号：</view>
				<input class="inpt" name="input" :value="NowSelectGoods.GoodsCode"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">单位：</view>
				<view class="inpt1"><input type="text" placeholder="点击获取" :value="NowSelectGoods.UnitName" disabled="true" style="text-align: left;" /><button
					 class="priceSear" data-target="UnitNameModal" @tap="showModal">查询</button>
					<view class="cu-modal" :class="modalName=='UnitNameModal'?'show':''">
						<view class="cu-dialog">
							<view class="cu-bar bg-white justify-end">
								<view class="content">请选择单位</view>
								<view class="action" @tap="hideModal">
									<text class="cuIcon-close text-red"></text>
								</view>
							</view>
							<view class="padding-xl">
								<view class="searchStore">
									<input placeholder="请输入名称" v-model="SearchUnitName" @input="filterUniName" />
									<button @tap="searchUnitName">搜索</button>
								</view>
								<view class="StoreListWrap">
									<view v-for="(item,index) in TempUnitNameList" :key="index" @tap="selectUnitName(index)">{{item.UnitName}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-form-group" v-if="orderType!=10">
				<view class="title">单价：</view>
				<view class="inpt1"><input type="text" placeholder="点击获取" v-model="NowSelectGoods.Price" style="text-align: left;" />
					<view class="cu-modal" :class="modalName=='PriceModal'?'show':''">
						<view class="cu-dialog">
							<view class="cu-bar bg-white justify-end">
								<view class="content">请选择单价</view>
								<view class="action" @tap="hideModal">
									<text class="cuIcon-close text-red"></text>
								</view>
							</view>
							<view class="padding-xl">
								<view class="StoreListWrap">
									<view v-for="(item,index) in PriceList" :key="index" @tap="selectPriceName(index)">{{item.ShowValue}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view><button class="priceSear" data-target="PriceModal" @tap="showModal">查询</button></view>
			</view>
			<!-- 	<view class="cu-form-group">
				<view class="title">批号：</view>
				<input class="inpt" name="input" disabled="true" ></input> -->
			<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			<!-- 	</view> -->
			<view class="cu-form-group">
				<view class="title">规格：</view>
				<input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.Spec"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			</view>

			<view class="cu-form-group" v-if="orderType==5||orderType==6">
				<view class="title">进价：</view>
				<input class="inpt" name="input" disabled v-model="InPrice"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">数量：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Qty"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">折扣：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Discount"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">税率：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Tax"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">库存：</view>
				<input class="inpt" name="input" disabled="true" :value="NowSelectGoods.stockqty"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">仓库：</view>
				<view class="inpt1"><input type="text" placeholder="点击获取" :value="SelectStoreObj.StoreName" disabled="true" style="text-align: left;"
					 data-target="StoreModal" @tap="showModal" />
					<view class="cu-modal" :class="modalName=='StoreModal'?'show':''">
						<view class="cu-dialog">
							<view class="cu-bar bg-white justify-end">
								<view class="content">请选择仓库</view>
								<view class="action" @tap="hideModal">
									<text class="cuIcon-close text-red"></text>
								</view>
							</view>
							<view class="padding-xl">
								<view class="searchStore">
									<input placeholder="请输入仓库名称" v-model="SearchStoreName" />
									<button @tap="searchStore">搜索</button>
								</view>
								<view class="StoreListWrap">
									<view v-for="(item,index) in StoreList" :key="item.StoreID" @tap="selectStore(index)">{{item.StoreName}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">生产日期：</view>
				<!-- <view @tap="open1()" class="inpt1">
					<input disabled="true" :value="ProductionDate.fulldate" :placeholder="datePlaceHolder" v-if='orderType!=10'></input>
					<input disabled="true" :value="SelectBrachObj.FDate" :placeholder="datePlaceHolder" v-if='orderType==10'></input> -->
				<!-- <input disabled="true" :value="SelectBrachObj.FDate" :placeholder="datePlaceHolder"></input> -->
				<!-- </view> -->
				<block v-if="NowSelectGoods.IsBatch && isBatchManger">
					<block v-if="orderType==5||orderType==6||orderType==9||orderType==14||orderType==15||orderType==16">
						<input disabled="true" :value="SelectBrachObj.FDate" placeholder="选择批号带出"></input>
					</block>
					<block v-else>
						<picker mode="date" :value="ProductionDate.fulldate" @change="DateChangeStart" v-if='orderType!=10'>
							<view class="picker">
								{{ProductionDate.fulldate}}
							</view>
						</picker>
					</block>
					<input disabled="true" :value="SelectBrachObj.FDate" :placeholder="datePlaceHolder" v-if='orderType==10'></input>
				</block>
				<block v-else>
					<input disabled="true" placeholder="不可选择"></input>
				</block>
			</view>
			<view class="cu-form-group">
				<view class="title">有效日期：</view>
				<!-- <view @tap="open2()" class="inpt1">
					<input disabled="true" :value="validityDate.fulldate" :placeholder="datePlaceHolder" v-if='orderType!=10'></input>
					<input disabled="true" :value="SelectBrachObj.FValidDate" :placeholder="datePlaceHolder" v-if='orderType==10'></input> -->
				<!-- <input disabled="true" :value="" :placeholder="datePlaceHolder" v-if='orderType==10'></input> -->
				<!-- </view> -->
				<block v-if="NowSelectGoods.IsBatch && isBatchManger">
					<block v-if="orderType==5||orderType==6||orderType==9||orderType==14||orderType==15||orderType==16">
						<input disabled="true" :value="SelectBrachObj.FValidDate" placeholder="选择批号带出"></input>
					</block>
					<block v-else>
						<picker mode="date" :value="validityDate.fulldate" @change="DateChangeEnd" v-if='orderType!=10'>
							<view class="picker">
								{{validityDate.fulldate}}
							</view>
						</picker>
					</block>
					<!-- <input disabled="true" :value="SelectBrachObj.FValidDate" :placeholder="datePlaceHolder" v-if='orderType==10'></input>
				<picker mode="date" :value="validityDate.fulldate" @change="DateChangeEnd" v-if='orderType!=10'>
					<view class="picker">
						{{validityDate.fulldate}}
					</view>
				</picker> -->
				</block>
				<block v-else>
					<input disabled="true" placeholder="不可选择"></input>
				</block>
			</view>
			<view class="cu-form-group" v-if="orderType==2">
				<view class="title">赠品:</view>
				<picker @change="PickerChange5" :value="index5" :range="picker5">
					<view class="picker">
						{{index5>-1?picker5[index5]:'单击选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">批号:</view>
				<input disabled v-if="!(NowSelectGoods.IsBatch && isBatchManger)" placeholder="不是批号商品" disabled=""></input>
				<input v-model="NowSelectGoods.BatchNo" v-else></input>
				<!-- <input class="inpt" name="input"></input> -->
				<button class="cu-btn  stop text-white" @tap="showModal" data-target='BrachModal' v-if="(isBatchManger && NowSelectGoods.IsBatch)">查询</button>
				<view class="cu-modal" :class="modalName=='BrachModal'?'show':''">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="content">请选择批号</view>
							<view class="action" @tap="hideModal">
								<text class="cuIcon-close text-red"></text>
							</view>
						</view>
						<view class="padding-xl">
							<view class="StoreListWrap">
								<view v-for="(item,index) in storeList" :key="index" @tap="selectBrach(index)" class="StoreListItem">
									<view class="Time"><text>批号:{{item.FBatchNo}}</text><text>数量：{{item.FQty}}</text></view>
									<view class="Time"><text>生产日期:{{item.FDate}}</text><text>有效日期:{{item.FValidDate}}</text></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-form-group" v-if="orderType!=10">
				<view class="title">备注：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Remark"></input>
			</view>
			<view class="cu-form-group">
				<!-- <button class="cu-btn  stop text-white" @tap="AddBillOrder">提交修改</button> -->
				<input class="inpt" name="input" disabled="true"></input>
				<button class="cu-btn  stop text-white" @tap="addSelectGoods">提交修改</button>
			</view>
		</view>
		<!-- 	<view class="cu-form-group">
			<view class="title">调入仓库:</view>
			<view class="inpt1"><input type="text" placeholder="点击获取" :value="SelectInStoreObj.StoreName" disabled="true"
				 style="text-align: left;" data-target="StoreInModal" @tap="showModal" />
				<view class="cu-modal" :class="modalName=='StoreInModal'?'show':''">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="content">请选择调入仓库</view>
							<view class="action" @tap="hideModal">
								<text class="cuIcon-close text-red"></text>
							</view>
						</view>
						<view class="padding-xl">
							<view class="searchStore">
								<input placeholder="请输入仓库名称" v-model="SearchInStoreName" />
								<button @tap="searchInStore">搜索</button>
							</view>
							<view class="StoreListWrap">
								<view v-for="(item,index) in StoreInList" :key="item.StoreID" @tap="selectInStore(index)">{{item.StoreName}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-form-group">
			<view class="title">调出仓库:</view>
			<view class="inpt1"><input type="text" placeholder="点击获取" :value="SelectOutStoreObj.StoreName" disabled="true"
				 style="text-align: left;" data-target="StoreOutModal" @tap="showModal" />
				<view class="cu-modal" :class="modalName=='StoreOutModal'?'show':''">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="content">请选择调出仓库</view>
							<view class="action" @tap="hideModal">
								<text class="cuIcon-close text-red"></text>
							</view>
						</view>
						<view class="padding-xl">
							<view class="searchStore">
								<input placeholder="请输入仓库名称" v-model="SearchOutStoreName" />
								<button @tap="searchOutStore">搜索</button>
							</view>
							<view class="StoreListWrap">
								<view v-for="(item,index) in StoreOutList" :key="item.StoreID" @tap="selectOutStore(index)">{{item.StoreName}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view> -->
		<view class="cu-modal" :class="isShowScanModel?'show':''">
			<view class="cu-dialog ls-main">
				<view class="cu-bar bg-ls justify-between">
					<view class="action">
						<view class="cuIcon-info text-white" v-show="false"></view>
					</view>
					<view class="content text-white">选择批号</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-white"></text>
					</view>
				</view>
				<view class="padding text-left bg-white ls-contain">
					<scroll-view scroll-y style="height: 400px;padding-bottom: 100px">
						<view class="ls-box" @tap="choosesGoods(index)" v-for="(item,index) in storeList" :key='index' :data-index="index">
							<view>批次号:{{item.Inventorybatch}}</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
		<uni-calendar ref="calendar1" :insert="false" @confirm="confirm1" />
		<uni-calendar ref="calendar2" :insert="false" @confirm="confirm2" />
	</view>
</template>
<script>
	import * as Api from '@/syApis/syAddOrder/syaddApis.js';
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
	export default {
		data() {
			return {
				//选择的商品
				NowSelectGoods: {},
				//添加的备注
				GoodsRemark: "",
				//商品库存
				GoodsStorm: 0,
				//商品税率
				Tax: 0,
				//商品
				GoodsQty: 0,
				//商品折扣
				GoodsDiscount: "",
				//仓库ID
				StoreID: "",
				//当前商品在原商品数组对应的位置
				index2: -1,
				picker2: [],
				// SelectStockNum: "",
				storeList: [],
				//仓库列表
				StoreList: [],
				//生产日期
				ProductionDate: {
					fulldate: ""
				},
				//有效日期
				validityDate: {
					fulldate: ""
				},
				index5: 0,
				picker5: ['否', '是'],
				orderType: 2,
				Inventorybatch: "",
				isShowScanModel: false,
				//日期palceholde
				datePlaceHolder: "点击选择日期",
				//当前选择的仓库
				SelectStoreObj: {
					StoreName: "",
					StoreID: ""
				},
				//模态框
				modalName: null,
				SearchStoreName: "",
				//批号过滤
				SearchBrachName: "",
				//当前选择的批号
				SelectBrachObj: {
					FBatchNo: "",
					FDate: "",
					FValidDate: ""
				},
				BillName: "",
				//多单位列表
				UnitNameList: [],
				//多单位搜索
				SearchUnitName: "",
				//价格跟踪
				PriceList: [],
				//价格跟踪搜索
				SearchPrice: "",
				isLoadState: false,
				TempUnitNameList: [],
				isNumQtStorm: false,
				isTipPrice: false,
				InPrice: 0,
				//当前选择的调入仓库条目
				SelectInStoreObj: {
					StoreName: "",
					StoreID: ""
				},
				//当前选择的调出仓库条目
				SelectOutStoreObj: {
					StoreName: "",
					StoreID: ""
				},
				//调入仓库名称搜索
				SearchInStoreName: "",
				//调出仓库名称搜索
				SearchOutStoreName: "",
				//调出仓库的列表
				StoreOutList: [],
				//调入仓库的列表
				StoreInList: [],
				ClientID: "",

				isBatchManger: true,
				//有效期
				validity: 0
			}
		},
		created() {

		},
		onLoad(options) {
			// console.log(JSON.parse(options.goodData));
			let goodData = uni.getStorageSync("ChangeGoodData", "");
			if (goodData != "") {
				this.NowSelectGoods = JSON.parse(goodData);
			}
			var that = this;
			let SystemSettingInfo = uni.getStorageSync("SystemSettingInfo", ""); //存储系统设置
			SystemSettingInfo = JSON.parse(SystemSettingInfo);
			SystemSettingInfo.forEach((item, index) => {
				if (item.SystemName == '是否允许负库存出库') {
					if (item.Value == "1") {
						that.isNumQtStorm = true;
					}

					// console.log(item.Value);
				}
				if (item.SystemName == '售价低于进价提示') {
					if (item.Value == "1") {
						that.isTipPrice = true;
					}
					// console.log(item.Value);
				}
				if (item.SystemName == '开启批号管理') {
					if (item.Value != "1") {
						that.isBatchManger = false;
					}
					// console.log(item.Value);
				}
			});
			console.log(goodData);
			this.StoreID = options.StoreID;
			this.index = options.selectIndex;
			this.orderType = options.orderType;
			this.ClientID = options.ClientID || "";
			console.log(this.NowSelectGoods);
			this.pullBillType(options.orderType + "");
			if (typeof options.Inventorybatch != 'string') {
				this.Inventorybatch = "";
			} else {
				this.Inventorybatch = options.Inventorybatch;
			}
			this.index5 = this.NowSelectGoods.IsGift;
			// if (this.orderType != 10 &&(this.NowSelectGoods.IsBatch && this.orderType==10)) {
			this.datePlaceHolder = "点击选择日期";
			let date = new Date();
			// let AddDate = new Date();
			// AddDate.setDate(AddDate.getDate()+this.NowSelectGoods.Days);
			// console.log(this.NowSelectGoods.Days);
			// let time =  date.getTime()+this.NowSelectGoods.Days*24*60*60*1000;
			// let AddDate = new Date(time);
			// console.log(AddDate.getFullYear());
			if (this.NowSelectGoods.validityDate != "" && this.NowSelectGoods.ProductionDate != "") {
				this.validity = this.getDays(this.NowSelectGoods.ProductionDate, this.NowSelectGoods.validityDate);
			}
			if (this.NowSelectGoods.ProductionDate != '') {
				this.ProductionDate.fulldate = this.NowSelectGoods.ProductionDate.split(" ")[0];
				this.SelectBrachObj.FDate = this.NowSelectGoods.ProductionDate.split(" ")[0];
			} else {
				if (this.NowSelectGoods.IsBatch && this.isBatchManger) {
					this.ProductionDate.fulldate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
					this.NowSelectGoods.ProductionDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
					this.SelectBrachObj.FDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
				}

			}
			if (this.NowSelectGoods.validityDate != '') {
				this.validityDate.fulldate = this.NowSelectGoods.validityDate.split(" ")[0];
				this.SelectBrachObj.FValidDate = this.NowSelectGoods.validityDate.split(" ")[0];
			} else {
				if (this.NowSelectGoods.IsBatch && this.isBatchManger) {
					this.validityDate.fulldate = this.getVarDate(this.validity);
					this.NowSelectGoods.validityDate = this.getVarDate(this.validity);
					this.SelectBrachObj.FValidDate = this.getVarDate(this.validity);
				}

			}

			if (this.orderType == 7) {
				this.SelectStoreObj.StoreID = options.StoreID;
			}
			// console.log(this.validityDate.fulldate);
			// }
			//  else {
			// 	this.datePlaceHolder = "不可选择日期";
			// 	this.SelectBrachObj.FDate = this.NowSelectGoods.ProductionDate;
			// 	this.SelectBrachObj.FValidDate = this.NowSelectGoods.validityDate;
			// 	this.SelectBrachObj.FBatchNo = this.NowSelectGoods.BatchNo;
			// }
			this.GetStoreMessage();
			this.XHGetBatchNoFollow();
			this.Get_GoodsUnitMessage();
			// this.SelectStockNum();

		},
		filters: {
			getFirstDay(value) {
				if (value != '' || typeof value != 'undefined') {
					return value.split(" ")[0];
				} else {
					return "";
				}
			}
		},
		components: {
			uniCalendar
		},
		methods: {
			//获取有效期
			getDays(startTime, EndTime) {
				startTime = this.getFirstDay(startTime);
				EndTime = this.getFirstDay(EndTime);
				startTime = startTime.replace(/-/g, '/');
				EndTime = EndTime.replace(/-/g, '/');
				//将时间转换成时间戳
				let startDate = new Date(startTime);
				let EndDate = new Date(EndTime);
				return (EndDate.getTime() - startDate.getTime()) / 1000 / 24 / 60 / 60;

			},
			//分割日期
			getFirstDay(value) {
				if (value != '' || typeof value != 'undefined') {
					return value.split(" ")[0];
				} else {
					return "";
				}
			},
			getVarDate(days) {
				console.log(days);
				let date = new Date();
				let time = date.getTime() + days * 24 * 60 * 60 * 1000;
				let AddDate = new Date(time);
				console.log(AddDate.getFullYear());
				// let date = new Date();
				var month = AddDate.getMonth() + 1;
				if (month < 10) {
					month = "0" + month
				}
				var day = AddDate.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				return AddDate.getFullYear() + "-" + month + "-" + day;
			},
			//生产日期修改后赋值有效日期
			changeBirToHasEat(val, days, type) {
				if (val == "" || typeof val == 'undefined') {
					return "";
				}
				val = val.replace(/-/g, '/');
				var date = new Date(val);
				let time = "";
				if (type == 0) {
					time = date.getTime() + days * 24 * 60 * 60 * 1000;
				} else {
					time = date.getTime() - days * 24 * 60 * 60 * 1000;
				}
				// let 
				let AddDate = new Date(time);
				var month = AddDate.getMonth() + 1;
				if (month < 10) {
					month = "0" + month
				}
				var day = AddDate.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				return AddDate.getFullYear() + "-" + month + "-" + day;
			},
			//有效日期修改后赋值生产日期
			changeHasEatToBir(val, days) {
				if (val == "" || typeof val == 'undefined') {
					return "";
				}
				val = val.replace(/-/g, '/');
				var date = new Date(val);
				let time = date.getTime() - days * 24 * 60 * 60 * 1000;
				let AddDate = new Date(time);
				var month = AddDate.getMonth() + 1;
				if (month < 10) {
					month = "0" + month
				}
				var day = AddDate.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				return AddDate.getFullYear() + "-" + month + "-" + day;
			},
			//调入仓库搜索
			searchInStore() {
				if (this.SearchInStoreName != "") {
					let Filter = "StoreName like '%" + this.SearchInStoreName + "%'";
					this.GetStoreMessage(Filter, 0);
				} else {
					this.GetStoreMessage();
				}
			},
			//调出仓库搜索
			searchOutStore() {
				if (this.SearchOutStoreName != "") {
					let Filter = "StoreName like '%" + this.SearchOutStoreName + "%'";
					this.GetStoreMessage(Filter, 1);
				} else {
					this.GetStoreMessage();
				}
			},
			//调入仓库选择
			selectInStore(index) {
				this.SelectInStoreObj = this.StoreInList[index];
				this.NowSelectGoods.StoreID2 = this.StoreInList[index].StoreID;
				this.modalName = null;
			},
			//调出仓库选择
			selectOutStore(index) {
				this.SelectOutStoreObj = this.StoreOutList[index];
				this.NowSelectGoods.StoreID = this.StoreOutList[index].StoreID;
				this.modalName = null;
			},
			//获取当前选择的商品的库存
			SelectStockNum() {
				let data = {
					StoreID: this.SelectStoreObj.StoreID,
					GoodsID: this.NowSelectGoods.GoodsID,
					BillName: this.BillName
				};
				var _this = this;
				Api.SelectStockNum(data, (res) => {
					if (res.data.ErrorMsg == "获取登录信息失败") {

					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						_this.GoodsStorm = res.data.ResultMsg;
						_this.NowSelectGoods.stockqty = res.data.ResultMsg;
					}
				});
			},
			DateChangeStart(e) {
				this.ProductionDate.fulldate = e.detail.value;
				this.NowSelectGoods.ProductionDate = e.detail.value;

				this.validityDate.fulldate = this.changeBirToHasEat(e.detail.value, this.validity, 0);
				this.NowSelectGoods.validityDate = this.changeBirToHasEat(e.detail.value, this.validity, 0);
			},
			DateChangeEnd(e) {
				this.validityDate.fulldate = e.detail.value;
				this.NowSelectGoods.validityDate = e.detail.value;

				this.ProductionDate.fulldate = this.changeBirToHasEat(e.detail.value, this.validity, 1);
				this.NowSelectGoods.ProductionDate = this.changeBirToHasEat(e.detail.value, this.validity, 1);
			},
			//多单位搜索
			searchUnitName() {
				let Filter = "";
				if (this.SearchUnitName != '') {
					Filter = "UnitName like '%" + this.SearchUnitName + "%'";
					this.Get_GoodsUnitMessage(Filter);
				} else {
					this.Get_GoodsUnitMessage();
				}
			},
			//多单位点击
			selectUnitName(index) {
				this.NowSelectGoods.UnitName = this.UnitNameList[index].UnitName;
				this.NowSelectGoods.urate = this.UnitNameList[index].urate;
				this.NowSelectGoods.UnitID = this.UnitNameList[index].UnitID;
				this.XH_Get_PriceFollowMessage(this.UnitNameList[index]);
				this.modalName = null;
			},
			//价格跟踪搜索
			searchPrice() {
				let Filter = "";
				if (this.SearchPrice != '') {
					Filter = "ShowValue like '%" + this.SearchPrice + "%'";
					this.XH_Get_PriceFollowMessage(this.NowSelectGoods, Filter);
				} else {
					this.XH_Get_PriceFollowMessage(this.NowSelectGoods);
				}
			},
			//多单位点击
			selectPriceName(index) {
				this.NowSelectGoods.Price = this.PriceList[index].Price;
				this.NowSelectGoods.PFPrice = this.PriceList[index].Price;
				this.modalName = null;
				this.SelectStockNum();
			},
			//价格跟踪
			XH_Get_PriceFollowMessage(priceItem, Filter = "") {
				let data = {
					GoodsID: priceItem.GoodsID,
					UnitID: priceItem.UnitID,
					BillName: this.BillName,
					URate: priceItem.urate,
					StoreID: this.SelectStoreObj.StoreID,
					ClientID: this.ClientID
				}
				var that = this;
				Api.XH_Get_PriceFollowMessage(data, function(res) {
					if (res.state) {
						if (res.data.ResultMsg != "") {
							that.PriceList = res.data.ResultMsg;
							if (that.isLoadState) {
								if (res.data.ResultMsg.length > 0) {
									res.data.ResultMsg.forEach((item, index) => {
										if (item.PriceType == '进价') {
											that.InPrice = item.Price;
										}
									});
									that.NowSelectGoods.Price = that.PriceList[0].Price;
								}
							} else {
								if (res.data.ResultMsg.length > 0) {
									res.data.ResultMsg.forEach((item, index) => {
										if (item.PriceType == '进价') {
											that.InPrice = item.Price;
										}
									});
									// that.NowSelectGoods.Price = that.PriceList[0].Price;
								}
								that.isLoadState = true;
							}
						} else if (res.data.ErrorMsg == '获取登录信息失败') {
							Api.showTip(res.data.ErrorMsg);
						} else {
							Api.showTip(res.data.ErrorMsg);
						}
					} else {

					}
				});
			},
			//查询商品多单位
			Get_GoodsUnitMessage(Filter = '') {
				let data = {
					GoodsID: this.NowSelectGoods.GoodsID,
					Filter: Filter
				}
				var that = this;
				Api.Get_GoodsUnitMessage(data, function(res) {
					if (res.state) {
						if (res.data.ResultMsg != "") {
							if (Filter != "") {
								that.TempUnitNameList = res.data.ResultMsg;
							} else {
								that.UnitNameList = res.data.ResultMsg;
								that.TempUnitNameList = res.data.ResultMsg;
							}
							if (that.UnitNameList.length > 0) {
								res.data.ResultMsg.forEach((item, index) => {
									if (item.UnitName == that.NowSelectGoods.UnitName) {
										that.XH_Get_PriceFollowMessage(item);
									}
								})
							}

						} else if (res.data.ErrorMsg == '获取登录信息失败') {
							Api.showTip(res.data.ErrorMsg);
						} else {
							Api.showTip(res.data.ErrorMsg);
						}
					} else {

					}
				});
			},
			//赋值单据类型
			pullBillType(str) {
				switch (str) {
					case "2":
						this.BillName = "采购入库单";
						break;
					case '7':
						this.BillName = "调拨单";
						break;
					case '5':
						this.BillName = "销售出库单";
						break;
					case '3':
						this.BillName = "采购退货单";
						break;
					case '6':
						this.BillName = "销售退货单";
						break;
					case '8':
						this.BillName = "其他入库单";
						break;
					case '9':
						this.BillName = "其他出库单";
						break;
					case '10':
						this.BillName = "盘点单";
						break;
					case '11':
						this.BillName = "收款单";
						break;
					case '12':
						this.BillName = "付款单";
						break;
					case '14':
						this.BillName = "配送申请单";
						break;
					case '15':
						this.BillName = "配送出库单";
						break;
					case '16':
						this.BillName = "配送退回单";
						break;
					default:
						break;
				}
			},
			filterUniName(e) {
				let value = e.detail.value;
				this.TempUnitNameList = [];
				var that = this;
				this.UnitNameList.forEach((item, index) => {
					if (item.UnitName.indexOf(value) > -1) {
						that.TempUnitNameList.push(item);
					}
				});
				if (that.TempUnitNameList.length == 0) {
					Api.showTip("查无数据");
				}
			},
			//搜索批号
			searchBrach() {
				if (this.SearchBrachName != '') {
					let Filter = "FBatchNo like '%" + this.SearchBrachName + "%'";
					this.XHGetBatchNoFollow(Filter);
				} else {
					this.XHGetBatchNoFollow();
				}
			},
			showModal(e) {
				if (e.currentTarget.dataset.target == "BrachModal") {
					if (!this.NowSelectGoods.IsBatch) {
						Api.showTip("不是批号商品");
						return;
					}
				}
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal() {
				this.modalName = null;
			},
			selectBrach(index) {
				this.SelectBrachObj = this.storeList[index];
				this.NowSelectGoods.BatchNo = this.storeList[index].FBatchNo;
				this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
				this.NowSelectGoods.validityDate = this.storeList[index].FValidDate;
				this.ProductionDate.fulldate = this.storeList[index].FDate;
				this.validityDate.fulldate = this.storeList[index].FValidDate;
				this.NowSelectGoods.stockqty = Math.round(this.storeList[index].FQty * 100) / 100;
				this.modalName = null;
			},
			//搜索仓库
			searchStore() {
				if (this.SearchStoreName != '') {
					let Filter = "StoreName like '%" + this.SearchStoreName + "%'";
					this.GetStoreMessage(Filter);
				} else {
					this.GetStoreMessage();
				}
			},
			//选择仓库
			selectStore(index) {
				this.SelectStoreObj = this.StoreList[index];
				this.NowSelectGoods.StoreID = this.SelectStoreObj.StoreID;
				this.modalName = null;
				this.SelectStockNum();
			},
			//获取当前选择的商品的库存
			// SelectStockNum() {
			// 	let data = {
			// 		StoreID: this.SelectStoreObj.StoreID,
			// 		GoodsID: this.NowSelectGoods.GoodsID,
			// 		BillName: this.BillName
			// 	};
			// 	var _this = this;
			// 	Api.SelectStockNum(data, (res) => {
			// 		if (res.data.ErrorMsg == "获取登录信息失败") {

			// 		} else if (res.data.ErrorMsg != "") {
			// 			Api.showTip(res.data.ErrorMsg);
			// 		} else {
			// 			_this.GoodsStorm = res.data.ResultMsg;
			// 			_this.NowSelectGoods.stockqty = res.data.ResultMsg;
			// 		}
			// 	});
			// },
			//选择仓库
			PickerChange2(e) {
				if (e.detail.value == -1) {
					this.index2 = 0;
				} else {
					this.index2 = e.detail.value;
				}
			},
			//获取批号
			XHGetBatchNoFollow() {
				let data = {
					StoreID: this.NowSelectGoods.StoreID,
					GoodsID: this.NowSelectGoods.GoodsID,
					BillName: this.BillName,
					Inventorybatch: this.Inventorybatch
				};
				var self = this;
				Api.XHGetBatchNoFollow(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != '') {

						} else {
							self.storeList = res.data.ResultMsg;
							self.storeList.forEach((item, index) => {
								self.storeList[index].FDate = self.getFirstDay(self.storeList[index].FDate);
								self.storeList[index].FValidDate = self.getFirstDay(self.storeList[index].FValidDate);
							})
						}
					}
				})
			},
			choosesGoods(index) {
				this.validityDate.fulldate = this.storeList[index].FDate;
				this.validityDate.fulldate = this.storeList[index].FValidDate;
				this.NowSelectGoods.FDate = this.storeList[index].FDate;
				this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
				this.NowSelectGoods.FValidDate = this.storeList[index].FValidDate;
				this.NowSelectGoods.validityDate = this.storeList[index].FValidDate;
				this.NowSelectGoods.BatchNo = this.storeList[index].FBatchNo;
			},
			//赠品选择
			PickerChange5(e) {
				this.index5 = e.detail.value
				this.NowSelectGoods.IsGift = this.index5;
			},
			open1() {
				if (this.orderType != 10) {
					this.$refs.calendar1.open();
				}

			},
			open2() {
				if (this.orderType != 10) {
					this.$refs.calendar2.open();
				}

			},
			confirm1(e) {
				this.ProductionDate = e;
				this.NowSelectGoods.ProductionDate = e.fulldate;
			},
			confirm2(e) {
				// var fulldate = e.detail.fulldate
				// console.log(e.detail.fulldate);
				console.log(e)
				this.validityDate = e,
					this.NowSelectGoods.validityDate = e.fulldate;
			},
			//获取仓库
			GetStoreMessage(Filter = '') {
				let data = {
					Filter: Filter
				}
				var that = this;
				Api.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							let responseData = res.data.ResultMsg;
							that.StoreList = res.data.ResultMsg;
							responseData.forEach(item => {
								if (that.NowSelectGoods.StoreID == item.StoreID) {
									that.SelectStoreObj = item;
								}
							})
						}
					} else {

					}
				});
			},
			//获取仓库
			GetInOutStoreMessage(Filter = '') {
				let data = {
					Filter: Filter
				}
				var that = this;
				Api.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							let responseData = res.data.ResultMsg;
							that.StoreInList = res.data.ResultMsg;
							that.StoreOutList = res.data.ResultMsg;
							responseData.forEach(item => {
								if (that.NowSelectGoods.StoreID == item.StoreID) {
									that.SelectInStoreObj = item;
								}
								if (that.NowSelectGoods.StoreID2 == item.StoreID) {
									that.SelectOutStoreObj = item;
								}
							})
						}
					} else {

					}
				});
			},
			//折扣改变事件
			changeZk(e) {
				console.log(e);
			},
			DiscountPrice() {
				this.NowSelectGoods.DiscountPrice = parseFloat(this.NowSelectGoods.Price) * (parseFloat(this.NowSelectGoods.Discount) /
					100) * (1 + parseFloat(
					this.NowSelectGoods.Tax) / 100);
			},
			//计算总价
			Amount() {
				this.NowSelectGoods.Amount = parseFloat(this.NowSelectGoods.Price) * parseFloat(this.NowSelectGoods.Qty) * (
					parseFloat(this.NowSelectGoods.Discount) / 100) * (1 + parseFloat(
					this.NowSelectGoods.Tax) / 100);
				// return  PFPrice;
			},
			//获取当前选择的商品
			addSelectGoods() {
				// if (this.SelectStoreObj.StoreID == '' && this.orderType != 10) {
				// 	Api.showTip("请选选择仓库");
				// 	return;
				// }
				if (parseFloat(this.NowSelectGoods.Qty) <= 0 || parseFloat(this.NowSelectGoods.Qty) == "") {
					Api.showTip("商品数量不能少于一件");
					return;
				}
				// console.log(this.NowSelectGoods.Qty ,this.NowSelectGoods.stockqty);
				// return;
				if (parseFloat(this.NowSelectGoods.Qty) > parseFloat(this.NowSelectGoods.stockqty) && !this.isNumQtStorm && (this.orderType ==
						3 || this.orderType ==
						5 || this.orderType == 9 ||
						this.orderType == 14 || this.orderType == 15
					)) {
					Api.showTip("当前库存不足");
					return;
				}

				if (this.NowSelectGoods.IsBatch && this.isBatchManger && this.NowSelectGoods.BatchNo == "") {
					Api.showTip("批号不能为空");
					return;
				}
				let DiscountStr = this.NowSelectGoods.Discount+'';
				if(DiscountStr.indexOf(".")>-1){
					Api.showTip("折扣只能是整数");
					return;
				}
				let TaxStr = this.NowSelectGoods.Tax+'';
				// console.log(this.NowSelectGoods.Tax+''.indexOf("."));
				if(TaxStr.indexOf(".")>-1){
					Api.showTip("税率只能是整数");
					return;
				}
				if(this.NowSelectGoods.IsGift==1){
					this.NowSelectGoods.Price = 0;
				}
				var _this = this;
				// if(this.orderType==5 || this.orderType ==6 || this.orderType == 9){
				if (this.orderType == 5) {
					if (parseFloat(this.NowSelectGoods.Price) < parseFloat(this.InPrice) && this.isTipPrice) {
						uni.showModal({
							title: '提示',
							content: "售价低于进价是否继续修改",
							success: function(res) {
								if (res.confirm) {
									// _this.NowSelectGoods.GoodsStorm = this.GoodsStorm;
									// console.log(this.NowSelectGoods);
									let data = {};
									data.index = _this.index;
									_this.DiscountPrice();
									_this.Amount();
									data.NewGoodInfo = JSON.stringify(_this.NowSelectGoods);
									_this.$eventHub.$emit('fireData', data);
									uni.navigateBack({
										delta: 1
									})
								} else if (res.cancel) {

								}
							}
						});
					} else {
						let data = {};
						data.index = _this.index;
						_this.DiscountPrice();
						_this.Amount();
						data.NewGoodInfo = JSON.stringify(_this.NowSelectGoods);
						_this.$eventHub.$emit('fireData', data);
						uni.navigateBack({
							delta: 1
						})
					}
				} else {
					let data = {};
					data.index = _this.index;
					_this.DiscountPrice();
					_this.Amount();
					data.NewGoodInfo = JSON.stringify(_this.NowSelectGoods);
					_this.$eventHub.$emit('fireData', data);
					uni.navigateBack({
						delta: 1
					})
				}

				// this.NowSelectGoods.GoodsStorm = this.GoodsStorm;
				// this.DiscountPrice();
				// this.Amount();
				// console.log(this.NowSelectGoods);

				// let data = {};
				// data.index = this.index;

				// data.NewGoodInfo = JSON.stringify(this.NowSelectGoods);
				// console.log(this.NowSelectGoods);
				// this.$eventHub.$emit('fireData', data);
				// uni.navigateBack({
				// 	delta: 1
				// })
			},
			//获取当前选择的商品的库存
			// 			SelectStockNum(GoodsID) {
			// 				let data = {
			// 					StoreID: this.StoreID,
			// 					GoodsID: GoodsID,
			// 					BillName: "采购入库单"
			// 				};
			// 				var _this = this;
			// 				Api.SelectStockNum(data, (res) => {
			// 					if (res.data.ErrorMsg == "获取登录信息失败") {
			// 
			// 					} else if (res.data.ErrorMsg != "") {
			// 						Api.showTip(res.data.ErrorMsg);
			// 					} else {
			// 						_this.GoodsStorm = res.data.ResultMsg;
			// 						_this.NowSelectGoods.GoodsStorm = res.data.ResultMsg;
			// 					}
			// 				});
			// 			},
			//计算折扣后商品价格
			computPrice(item) {
				item.PFPrice = item.PFPrice * item.Qty * (item.Discount / 100) * (1 + item.Tax / 100);
				return item;
			}
		}
	}
</script>

<style>
	.stop {
		background: rgba(124, 170, 216, 1) !important;
	}

	.inpt1 {
		flex: 1;
		text-align: left;
		align-items: center;
		display: flex;
	}

	/* 弹框样式 */
	.padding-xl .searchStore {
		display: flex;
		width: 100%;
		margin: auto;
		height: 45px;
		padding-top: 5px;
		font-size: 14px;
	}

	.padding-xl .searchStore input {
		flex: 1;
		height: 35px;
		border: 1px solid #CCC;
		border-top-left-radius: 5px;
		border-bottom-left-radius: 5px;
		padding-left: 10px;
	}

	.padding-xl {
		padding: 10px;

	}

	.padding-xl .searchStore button {
		font-size: 14px;
		color: #FFF;
		padding-left: 8px;
		padding-right: 8px;
		height: 35px;
		line-height: 35px;
		border-radius: 0px;
		border-top-right-radius: 5px;
		border-bottom-right-radius: 5px;
		text-align: center;
		background: rgba(124, 170, 216, 1);
	}

	.padding-xl .StoreListWrap {
		height: 250px;
		overflow: auto;
	}

	.padding-xl .StoreListWrap view {
		height: 40px;
		line-height: 40px;
		text-align: left;
		border-bottom: 1px solid #CCC;
		padding-left: 8px;
	}

	.cu-form-group {
		padding: 1px 10px !important;
		height: 40px;
		line-height: 40px;
		min-height: 40px;
	}

	.cu-form-group uni-picker .picker {
		text-align: left;
	}

	.cu-form-group .priceSear {
		width: 50px;
		padding: 0px;
		height: 28px;
		line-height: 28px;
		font-size: 12px;
		border-radius: 5px;
		background: rgba(124, 170, 216, 1);
		color: #FFF;
	}


	.padding-xl .StoreListWrap .StoreListItem {
		height: 60px;
		line-height: 30px;
		border-bottom: 1px solid #CCC;
	}

	.padding-xl .StoreListWrap .StoreListItem view {
		display: flex;
		border-bottom: none;
		height: 30px;
		line-height: 30px;
	}

	.padding-xl .StoreListWrap .StoreListItem view text {
		flex: 1;
	}
</style>
